<template>
    <t-form>
        <t-form-item label="随机数长度">
            <t-input-number v-model="data" theme="normal" />
        </t-form-item>
        <t-form-item label="生成的随机数">
            <div>
                {{ generateRandowNumber(Number(data)) }}
            </div>
        </t-form-item>
    </t-form>
</template>
<script setup lang="ts">
import {ref} from "vue";
const data = ref();

/**
 * 生成随机数
 * @param {Number} length // 随机数长度
 * @returns {Number} // 符合长度的随机数字
 */
 const generateRandowNumber = (length: number) => {
  if(!length) return '';
  const multipleNum = new Array(length).fill(10).reduce((acc) => {
    return acc * 10;
  }, 1);
  const randomNum = Math.floor(Math.random() * multipleNum);
  return randomNum;
};
</script>